<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ include file="/WEB-INF/views/include/head.jsp"%>
<%@ taglib uri="/WEB-INF/tlds/att.tld" prefix="att"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="${staticPath}/css/layout.css" type="text/css" rel="stylesheet" />
<link href="${staticPath}/css/images.css" type="text/css" rel="stylesheet" />
<script src="${staticPath}/lib/art-template/template.js"></script>

</head>
<body style="background-color: #fff;">
<script type="text/javascript">
	(function($){
		   $.fn.getAttachmentInfo = function(key){
			   var obj = $('[name="key"][value="'+key+'"]').parent();
			   return obj.find('[name="key"]').data('ossp-attachment-contr');
		   }
	})(jQuery);
	function Att_OpenDialog(th){
		var obj = cacheAtta = $(th).parent();
		var dialogURL = obj.find('[name="dialogURL"]').val();
		var r=Math.random();
		obj.find('[name="random"]').val(r);
		
		var dialogSty = 'dialogWidth=800px;dialogHeight=500px;center=yes;resizable=no;status=no;';
		vReturnValue = window.showModalDialog(dialogURL+"?r="+r,window,dialogSty);
		if(vReturnValue){
			var ids = new Array();
			for (var i=0, file; file=vReturnValue.files[i]; i++){
				ids[i]=file.attid;
	    	}
			vReturnValue.o = {};
			vReturnValue.o.formatFileSize = function(size){
    			return (size / 1000)+'KB';
    		};
    		vReturnValue.o.formatFileIcon = function(fileType){
				switch(fileType){
					case "application/msword":return "doc_1.png";
					case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":return "doc_1.png";
					case "application/vnd.ms-excel":return "xls_1.png";
					case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":return "xls_1.png";
					case "application/vnd.ms-powerpoint":return "pdf_1.png";
					case "application/pdf":return "pdf_1.png";
					case "text/plain":return "text_1.png";
					case "application/x-jpg":return "img_1.png";
					case "application/x-ico":return "img_1.png";
					case "application/x-bmp":return "img_1.png";
					case "image/gif":return "img_1.png";
					case "image/png":return "img_1.png";
					case "image/jpeg":return "img_1.png";
					default:return "documents_1.png";
				}
    		};
			var html = template('file-view-tmp', vReturnValue);
			$("#file-view-janathan").html(html);
			obj.find('[name="key"]').data('ossp-attachment-contr',ids);
		}
	}
	function getVal(id,random){
		var obj = $('[name=random][value="'+random+'"]').parent();//$('#ossp-attachment-contr');
		return obj.find('[name="'+id+'"]').val();
	}
</script>
<script id="file-view-tmp" type="text/html">
	{{each files as file}}
		  <tr>
               <td><span class="preview img_preview"><img src="${staticPath}/images/icon/fileIcon/{{o.formatFileIcon(file.fileType)}}" height="26" width="26"></span></td>
               <td><p class="name">{{file.name}}</p></td>
               <td><p class="size">{{o.formatFileSize(file.size)}}</p> </td>
               <td> 
					<a href="${contextPath}{{file.url}}" title="{{file.name}}">
                   <button type="submit" class="btn btn-warning img_padding_btn img_margin btn_3">
                       <i class="glyphicon glyphicon-download-alt"></i>
                       <span>&nbsp;下&nbsp;载</span>
                   </button>
					</a>
                </td>
           </tr>
	{{/each}}
</script>
<div class="bs-example" name="ossp-attachment-contr">
	<input type="hidden" name="handlerUploadURL" value="/ossp-web/sys/att/upload">
	<input type="hidden" name="handlerDownloadURL" value="">
	<input type="hidden" name="downloadFileListURL" value="/ossp-web/sys/att/attr/download/list">
	<input type="hidden" name="dialogURL" value="/ossp-web/sys/att/upload/dialog">
	<input type="hidden" name="modleName" value="2">
	<input type="hidden" name="key" value="janathan">
	<input type="hidden" name="soureBillID" value="1">
	<input type="hidden" name="accept" value="">
	<input type="hidden" name="maxFileSize" value="100000000">
	<input type="hidden" name="random" value="">
	<button type="button" class="btn btn-info fileinput-button img_padding_btn img_btn_info btn_3" onclick="Att_OpenDialog(this)">上传</button>
    <table role="presentation" class="img_table padding">
       <tbody id="file-view-janathan">
       </tbody>
   </table>
</div>
</body>
</html>